package org.dormi.learn.product.domain.material.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

import java.util.Arrays;

/**
 * 产品类型
 *
 * @author : dormi330
 * @version : 1.0
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
public enum PhysicalForm {

    // 实体
    PHYSICAL("PHYSICAL", "physical"),
    // 服务
    SERVICE("PHYSICAL", "service"),
    // 虚拟
    VIRTUAL("PHYSICAL", "virtual"),
    ;

    PhysicalForm(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @JsonCreator
    public static PhysicalForm findValue(@JsonProperty("code") String code) {
        return Arrays.stream(PhysicalForm.values())
                .filter(pt -> pt.code.equals(code))
                .findFirst()
                .orElse(null);
    }

    private final String code;
    private final String name;

}
